//
//  TripArrangeViewModel.swift
//  ImGuider X
//
//  Created by 陆涛 on 2018/9/29.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit

class TripArrangeViewModel: NSObject {

    var trip:Trip?
    
    var days:[Day]? {
        
        
        guard let trip = trip else { return nil }
        
        return trip.cities?.reduce([], { (array, city) -> [Day] in
            
            
            if let days = city.days {
                
                for i in 0..<days.count {
                    
                    let day = days[i]
                    
                    day.inCity = city.cityName
                }
                return array + days
            }
            
            return array
        })
    }
    
    var day:Day?
    
//    var calendars:[Calendar]? {
//        
//        var array = day?.calendars ?? []
//        
//        if let hotel = day?.hotel {
//            
//            array.append(hotel)
//        }
//        
//        if array.count > 0 {
//            return array
//        }
//        
//        return nil
//    }
    
    var reloadDay:(()->Void)?
    
    var currentDay = 0 {
        
        didSet {
            
            if let day = days?[currentDay] {
                
                self.day = day;
                
                self.reloadDay?()
            }
        }
    }
}
